<?php


namespace app\home\controller\user;


use app\home\controller\Base;
use app\home\model\dealer\Dealer;
use app\home\service\CodeService;
use app\home\service\TokenService;

class UserSet extends Base
{
    protected $model;
    protected $uid;
    public function __construct(Dealer $model)
    {
        $this->model = $model;
        $this->uid = TokenService::getUserInfoFromToken('u_id');
        $this->param = input('post.');
    }


    public function getUserInfo(){
        if(is_array($this->uid))  return $this->uid;
        $res =$this->model->where('u_id',$this->uid)->find();
        return !empty($res) ? CodeService::response(200,'获取成功',$res) : CodeService::SERVER_ERROR_TRY_AGAIN_LATER;
    }



    /**
     * 退出登录
     * @param string token
     * @return array
     */
    public function signOut(){
        if(is_array($this->uid))  return $this->uid;
        return $this->model->save(['token'=>null],['u_id'=> $this->uid]) ? CodeService::Response(200,'退出登录成功') : CodeService::SERVER_ERROR_TRY_AGAIN_LATER;
    }


}
